<?php

namespace App\Admin\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use \App\Models\Photo;
use Encore\Admin\Facades\Admin;
use App\Services\MakePhotoThumbnail\MakePhotoThumbnail;
use App\Admin\Actions\DivinationAction\MakeDeepThink;

class PhotosController extends AdminController
{
    protected $title = '银子岩屏保设置';
    
    protected function grid()
    {
        $grid = new Grid(new Photo());

	    $grid->disableExport();
	
	    $grid->column('id', 'ID');
	    $grid->column('title', '屏保名称');
	     $grid->column('image', '图片')->lightbox(['width' => 50, 'height' => 50]);

	    $grid->column('created_at', '创建时间')->display(function () {
		    return $this->created_at->toDatetimeString();
	    });
	
	    $grid->disableRowSelector();
        return $grid;
    }

   
	
	 protected function detail($id)
    {
        $show = new Show(Photo::findOrFail($id));
        return $show;
    }
	
    protected function form()
    {
        $form = new Form(new Photo());
	    $form->text('title', '屏保名称');
	    $form->image('image', '屏保图')->uniqueName()->help('NOTE：保证清晰的前提下尽可能压缩体积');
	    
	    $this->formSaved($form);
        return $form;
    }

    protected function formSaved(Form $form)
	{
		$form->saved(function () use ($form) {
			
			
			app(MakePhotoThumbnail::class, ['photo' => $form->model()])->make();
		});
	}

   
}
